﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DTO;
using BUS;

namespace GUI
{
    public partial class frmSuaKhachHang : DevComponents.DotNetBar.Metro.MetroForm
    {
        public delegate void ChinhSua(KhachHangDTO khDTO);
        public event ChinhSua KhiChinhSua = null;

        public frmSuaKhachHang()
        {
            InitializeComponent();
        }

        private int _MaKhachHang;

        public int MaKhachHang
        {
            get { return _MaKhachHang; }
            set { _MaKhachHang = value; }
        }

        private void btnHuyBo_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnDongY_Click(object sender, EventArgs e)
        {
            try
            {
                KhachHangDTO khDTO = LayThongTin();
                if (KhiChinhSua != null)
                {
                    KhiChinhSua(khDTO);
                }                
                this.Close();
            }
            catch (Exception ex)
            {
                DevComponents.DotNetBar.MessageBoxEx.Show("Lỗi dữ liệu cập nhật nhân viên " + ex.Message);
            }
        }

        KhachHangDTO LayThongTin()
        {
            KhachHangDTO khDTO = new KhachHangDTO();
            khDTO.MaKhachHang = MaKhachHang;
            khDTO.TenKhachHang = txtTenKhachHang.Text;
            khDTO.SoDienThoai = this.txtSoDienThoai.Text;
            khDTO.DiaChi = this.txtDiaChi.Text;
            khDTO.Email = this.txtEmail.Text;
            khDTO.GhiChu = this.txtGhiChu.Text;

            return khDTO;
        }

        private void LayThongTinKhachHangTheoMa()
        {
            KhachHangBUS khBUS = new KhachHangBUS();
            KhachHangDTO khDTO = new KhachHangDTO();
            LoaiNhanVienBUS lnvBUS = new LoaiNhanVienBUS();
            LoaiNhanVienDTO lnvDTO = new LoaiNhanVienDTO();
            khDTO = khBUS.LayThongTinKhachHangTheoMa(MaKhachHang);
            this.txtTenKhachHang.Text = khDTO.TenKhachHang;
            this.txtSoDienThoai.Text = khDTO.SoDienThoai.ToString();
            txtDiaChi.Text = khDTO.DiaChi;
            this.txtEmail.Text = khDTO.Email;
            this.txtGhiChu.Text = khDTO.GhiChu;
        }

        private void frmSuaKhachHang_Load(object sender, EventArgs e)
        {
            LayThongTinKhachHangTheoMa();
        }
    }
}